// The Vue build version to load with the `import` command
import Vue from 'vue'
import Vuex from 'vuex'
import App from './App'
import routes from './router/index.js'
import * as filters from './common/filter'
import {
  DevicePlugin,
  ToastPlugin,
  AlertPlugin,
  ConfirmPlugin,
  LoadingPlugin,
  WechatPlugin
} from 'vux'
import AjaxPlugin from './config/baseHttp'
import Toast from './plugin/index'

import utils from './utils/index.js'

import mixins from './mixins/index'

window.utils = utils

Vue.mixin(mixins) // 混入公共class,方法等;

Vue.use(AjaxPlugin)
Vue.use(Toast)
Vue.use(DevicePlugin)
Vue.use(ToastPlugin)
Vue.use(AlertPlugin)
Vue.use(ConfirmPlugin)
Vue.use(LoadingPlugin)
// AjaxPlugin 和vue-resource一样在组件内使用this.$http进行调用了。
// 微信js sdk
Vue.use(WechatPlugin)
Vue.use(Vuex)

const store = new Vuex.Store({}) // 这里你可能已经有其他 module

store.registerModule('vux', { // 名字自己定义
  state: {
    isLoading: false
  },
  mutations: {
    updateLoadingStatus (state, payload) {
      state.isLoading = payload.isLoading
    }
  }
})

routes.beforeEach(function (to, from, next) {
  store.commit('updateLoadingStatus', {
    isLoading: true
  })
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

routes.afterEach(function (to) {
  setTimeout(function () {
    store.commit('updateLoadingStatus', {
      isLoading: false
    })
  }, 500)
})

// // 点击延迟
// FastClick.attach(document.body)

Vue.config.productionTip = true

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

/* eslint-disable no-new */
new Vue({
  router: routes,
  store,
  render: h => h(App)
}).$mount('#app')
